import request from "../utils/request";

interface IResponse{
    statusCode:number;
    message:string;
}

interface IUserResponse extends IResponse{
    data:{
        userInfo:UserInfo;
        token:string;
    }
}
interface UserInfo{
    _id:string;
    imageUrl:string;
    isShow:boolean;
    name:string;
    email:string;
    jurisdiction:string[];
}
export const login = ({username,password}):Promise<IUserResponse>=>{
    let url='/api/v1/user/login'
    return request.post(url,{username,password})
}

/**
 * 用户注册 register
 */
export const register = ({email,username,password,password2,code}):Promise<IResponse>=>{
    let url='/api/user/register'
    return request.post(url,{email,username,password,password2,code})
}
/**
 * 检测邮箱是否可用 emailIsValidate
 */
export const emailIsValidate =(email:string) :Promise<IResponse>=>{
    let url ='/api/user/emailIsValidate'
    return request.post(url, {email})
}
/**
 * 获取验证码 getCode
 */

interface ICode {
    data: {
        id:string
    };
    message: string;
    statusCode: number;
}
export const getEmailCode =(email:string) :Promise<ICode>=>{
    let url = '/api/user/getCode'
    return request.post(url,{email})
}

/**
 * 修改头像
 */
export const updaterAvatar =(data)=>{
    let url ='/api/user/updateAvatar'
    return request.post(url,data)
}
/**
 * 上传头像
 */
export const uploadAvatar =(data)=>{
    let url ='/api/upload/store'
    return request.post(url,data)
}
/**
 * 修改密码 changePwd
 */
export const changePwd =(data) =>{
    let url ='/api/v1/user/updatePwd'
    return request.post(url,data)
}
